package dfbz.homework7;

import java.util.concurrent.locks.ReentrantLock;

public class MyThread implements Runnable {
    private static Integer sit = 80;
    ReentrantLock lock=new ReentrantLock();
    @Override
    public void run() {
        while (true){
            try {
                lock.lock();
                Thread.sleep(300);
                sit--;
                if (sit>=0){
                    System.out.println(Thread.currentThread().getName()+"上车--座位剩余:"+sit+"个");
                    if(sit==0){
                        System.out.println("无座位了");
                        System.exit(0);
                    }
                }
                lock.unlock();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}